package com.miracle.pagestatedemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.miracle.pagestate.PageStateView
import com.miracle.pagestatedemo.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var mBinding: ActivityMainBinding
    private lateinit var pageStateView: PageStateView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mBinding.root)

        pageStateView = PageStateView.bindView(this, R.id.rl_content)
        pageStateView.setEmptyView(R.layout.empty_layout)
        initListener()
    }


    private fun initListener() {
        mBinding.tvNormal.setOnClickListener {
            pageStateView.showContentView()
        }
        mBinding.tvLoading.setOnClickListener {
            pageStateView.showLoadingView()
        }
        mBinding.tvEmpty.setOnClickListener {
            pageStateView.showEmptyView()
        }
        mBinding.tvNetError.setOnClickListener {
            pageStateView.showNetErrorView()
        }
        mBinding.tvServerError.setOnClickListener {
            pageStateView.showServerErrorView()
        }
    }
}